<?php
/**
 * Created by PhpStorm.
 * User: 小灰灰
 * Date: 2023-03-09
 * Time: 10:19:34
 * Info: 清除缓存服务类
 */

namespace app\common\service\admin;

use think\facade\Cache;
use think\facade\Session;

class CacheClearService
{

    /**
     * 清除后台菜单缓存
     *
     * @param null $adminId
     *
     * @return bool
     */
    public static function clearMenu($adminId = null)
    {
        if (empty($adminId)) {
            Cache::tag('initAdmin')->clear();
        } else {
            Cache::delete('initAdmin_'.$adminId);
        }
    }

    public static function clearAdminMenu($adminId = null)
    {
        if (empty($adminId)) {
            Cache::tag('cacheAdminMenu')->clear();
        } else {
            Cache::delete('cacheAdminMenuId'.$adminId);
        }

        return true;
    }

    /**
     * 清除系统设置缓存
     * @return bool
     */
    public static function clearSystemConfig($clearAll = false)
    {
        if ($clearAll) {
            //清除所有缓存，并退出重新登录
            Cache::clear();
            Session::clear();
        } else {
            Cache::delete('cacheSystemConfig');
        }

        return true;
    }

    /**
     * 清除管理员信息
     * @return void
     */
    public static function clearAdminInfo($adminId)
    {

    }
}
